import java.time.Period;

class Son implements Cloneable{
    public int data = 9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Data implements Cloneable{
    public int data1;
    public int data2;

    public Son data3;
    public Data(int data1, int data2) {
        this.data1 = data1;
        this.data2 = data2;
        data3 = new Son();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //return super.clone();
        Data tmp = (Data) super.clone();//浅拷贝

        tmp.data3 = (Son) this.data3.clone();//克隆对象的对象

        return tmp;
    }
}


public class Test4 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Data t1 = new Data(11,22);
        Data t2 = (Data) t1.clone();


        System.out.println("修改之前："+t1.data3.data);
        System.out.println("修改之前："+t2.data3.data);
        t2.data3.data = 999999;//通过克隆得到的对象去修改
        System.out.println("修改之后："+t1.data3.data);
        System.out.println("修改之后："+t2.data3.data);

    }
    public static void main1(String[] args) throws CloneNotSupportedException {
        Data t1 = new Data(11,22);

        Data t2 = (Data) t1.clone();
    }
}
